//
//  ViewController.m
//  运行时自定义KVO
//
//  Created by Hello Cai on 2019/11/25.
//  Copyright © 2019 Hello Cai. All rights reserved.
//

#import "ViewController.h"
#import "Person.h"
#import "NSObject+kvo.h"
#import "HHPerson.h"

@interface ViewController ()
@property(nonatomic, strong)Person *p;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    Person *p = [[Person alloc] init];
    p.name = @"wangcai";
    [p K_addObserver:self forKeyPath:@"name" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
    self.p = p;
    
    
//    HHPerson *pp = [[HHPerson alloc] init];
//    pp.name = @"kkk";
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    
    self.p.name = @"zhangsan";
}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
    
    NSLog(@"--%@", change);
}

@end
